package cn.nvrelax.cloudnote.syskit;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 程序描述：配置拦截,必须Token合法才可以
 * 所有需鉴权的api，URL写法都要以/api/开头
 * 创建时间：2018/12/17 20:31
 * 编码：nvRelax
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public TokenInterceptor getTokenInterceptor() {
        return new TokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //支持的是ant风格的路径匹配
        registry.addInterceptor(getTokenInterceptor()).addPathPatterns(
                "/api/**");
    }
}
